package e.odbo.data.sample.lock;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.I_Session;
import e.odbo.data.dao.BaseDAO;
import e.odbo.data.dao.table.I_TableSentenceBuilder;
import e.odbo.data.dao.table.TableDefinition;
import e.odbo.data.dao.table.Field;
import com.openbravo.data.loader.serialize.Datas;
import e.odbo.data.format.Formats;
import com.openbravo.data.loader.serialize.DataWrite;
import com.openbravo.data.loader.serialize.DataRead;


public class OdbOLockDAO extends BaseDAO<OdbOLock> {


    public OdbOLockDAO(I_Session s, I_TableSentenceBuilder tableBuilder) {
        super(s, tableBuilder);
    }

    @Override
    public Class getSuportClass() {
        return OdbOLock.class;
    }

// tableDefinition table:	odbo_lock 	build time :2019-07-01 07:49:07.253

    @Override
    public TableDefinition getTable() {
        TableDefinition odbo_lockTableDefinition=new TableDefinition("odbo_lock" ,new Field[]{
                new Field(OdbOLock.ID,Datas.STRING,Formats.STRING),//(PK)
                new Field(OdbOLock.LOCK_OWNER,Datas.STRING,Formats.STRING),//(notNull)
                new Field(OdbOLock.LOCK_TIME,Datas.TIMESTAMP,Formats.TIMESTAMP)//
        }, new int[] {0}
        );
        return odbo_lockTableDefinition;
    }

    @Override
    public void writeInsertValues(DataWrite dp,OdbOLock obj) throws BasicException {
        dp.setString(1,obj.getId());
        dp.setString(2,obj.getLockOwner());
        dp.setTimestamp(3,obj.getLockTime());
    }


    public OdbOLock readValues(DataRead dr,OdbOLock obj) throws BasicException {
        if(obj==null)
            obj = new OdbOLock();
        obj.setId(dr.getString(1));
        obj.setLockOwner(dr.getString(2));
        obj.setLockTime(dr.getTimestamp(3));
        return obj;
    }


}